<?php

namespace App\Models;

use Dcat\Admin\Traits\HasDateTimeFormatter;

use Illuminate\Database\Eloquent\Model;

class Oauth extends Model
{
	use HasDateTimeFormatter;

    protected $table = 'oauth';

    /**
     * @param int $user_id
     * @param string $openid
     * @param string $nickname
     * @return bool
     */
    public static function addData(int $user_id,string $openid,string $nickname): bool
    {
        $model = new self;
        $model->user_id = $user_id;
        $model->platform = '微信小程序';
        $model->type = 'wx_app';
        $model->openid = $openid;
        $model->openname = $nickname;
        return $model->save();
    }

    /**
     * @param string $type
     * @param string $openid
     * @param string $platform
     * @return mixed
     */
    public static function findUser(string $type, string $openid, string $platform = '微信小程序'){
       return self::where('type',$type)->where('openid',$openid)->where('platform',$platform)->first();
    }

}
